<template>
  <van-dialog
    use-slot
    :showConfirmButton="false"
    @close="closeDialog"
    :show="open"
  >
    <div>
      <van-picker
        value-key="name"
        title="添加员工"
        show-toolbar
        :columns="columns"
        @confirm="onConfirm"
        @cancel="onCancel"
      >
      </van-picker>
    </div>
  </van-dialog>
</template>
  
<script>
import { studentList, putCourseStudentList } from "@/common/api/teaching.js";
export default {
  components: {},
  props: {
    open: {
      type: Boolean,
      default: false,
    },
    course: {
      type: Object,
    },
  },
  data() {
    return {
      columns: [],
    };
  },
  watch: {
    open(e) {
      if (e) {
        // 获取学生列表
        console.log("获取学生列表", this.course);
        this.getStudentList();
      }
    },
  },
  methods: {
    // 获取学生列表
    async getStudentList() {
      let res = await studentList(this.course.school_id, this.course.course_id);
      this.columns = res.data;
    },
    closeDialog() {
      // 关闭弹框
      this.$emit("update:open", false);
    },
    async onConfirm(value) {
      console.log(value.detail);
      uni.showLoading({
        mask: true,
        title: "添加中",
      });
      let res = await putCourseStudentList({
        schoolId: this.course.school_id,
        courseId: this.course.course_id,
        students: [{ studentId: value.detail.value.student_id }],
      });
      uni.hideLoading();
      uni.showToast({
        title: "添加成功",
        icon: "success",
        duration: 1500,
      });
      this.closeDialog();
      this.$emit("refresh", true);
    },
    onCancel() {
      this.closeDialog();
    },
  },
  created() {},
  onReady() {},
};
</script>
  <style scoped lang='scss'>
</style>
  